/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gui.usergui;

import stendcontrol.Experiment;
import stendcontrol.Func;
import stendcontrol.Param;
import stendcontrol.SaveLoadExpContainer;

/**
 *
 * @author minaev
 */
public class SaveExpFrame extends javax.swing.JFrame {

    Experiment exp;
    SaveLoadExpContainer exp_cont;
    /**
     * Creates new form SaveExpFrame
     */
    public SaveExpFrame(Experiment exp,SaveLoadExpContainer exp_cont) {
        this.exp = exp;
        this.exp_cont = exp_cont;
        initComponents();
        this.setTitle("Сохранение: "+exp.getExpName());
        jl_title.setText("Сохранение: "+exp.getExpName());
        this.setLocationRelativeTo(null);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jl_title = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jcb_sources = new javax.swing.JComboBox();
        jPanel3 = new javax.swing.JPanel();
        jb_save = new javax.swing.JButton();
        jb_cancel = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Сохранение эксперимента");
        setResizable(false);

        jl_title.setText("Сохранение эксперимента");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jl_title)
                .addContainerGap(338, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jl_title)
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Выберите приемник эксперимента"));

        jcb_sources.setModel(exp_cont.getSaveLoaders());

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jcb_sources, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap(13, Short.MAX_VALUE)
                .addComponent(jcb_sources, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jb_save.setText("Сохранить");
        jb_save.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jb_saveActionPerformed(evt);
            }
        });

        jb_cancel.setText("Отмена");
        jb_cancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jb_cancelActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addComponent(jb_cancel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jb_save))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jb_save)
                    .addComponent(jb_cancel)))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jb_saveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jb_saveActionPerformed
        int sel = jcb_sources.getSelectedIndex();
        if(sel!=-1){
            exp_cont.saveExp(exp, sel);
            dispose();
        }
    }//GEN-LAST:event_jb_saveActionPerformed

    private void jb_cancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jb_cancelActionPerformed
        dispose();
    }//GEN-LAST:event_jb_cancelActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(SaveExpFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(SaveExpFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(SaveExpFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(SaveExpFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                int cnt = 2000;
                double[] x = new double[cnt];
                double[] y0 = new double[cnt];
                double[] y1 = new double[cnt];
                double[] y2 = new double[cnt];
                double[] y3 = new double[cnt];

                for (int i = 0; i < cnt; i++) {
                    x[i] = i;
                    y0[i] = Math.sin(i / 250.0) * 200;
                    y1[i] = Math.sin(i / 200.0) * 180;
                    y2[i] = Math.sin(i / 150.0) * 160;
                    y3[i] = Math.sin(i / 100.0) * 140;
                }
                Func fnc0 = new Func("test1", Func.F_OTHER, y0, x);
                Func fnc1 = new Func("test2", Func.F_OTHER, y1, x);
                Func fnc2 = new Func("test3", Func.F_OTHER, y2, x);
                Func fnc3 = new Func("test4", Func.F_OTHER, y3, x);

                Experiment test_exp = new Experiment("test_exp_result");

                test_exp.addResultFunc(fnc0, false);
                test_exp.addResultFunc(fnc1, false);
                test_exp.addResultFunc(fnc2, true);
                test_exp.addResultFunc(fnc3, false);

                test_exp.addResultParam(new Param("Параметр 1", Param.P_OTHER, 3));
                test_exp.addResultParam(new Param("Параметр 2", Param.P_OTHER, 300));
                test_exp.addResultParam(new Param("Параметр 3", Param.P_OTHER, 400));
                test_exp.addResultParam(new Param("Параметр 4", Param.P_OTHER, 3.1415));
                test_exp.addResultParam(new Param("Параметр 5", Param.P_OTHER, 234));
                test_exp.addResultParam(new Param("Параметр 6", Param.P_OTHER, 362.0));
                test_exp.addResultParam(new Param("Параметр 7", Param.P_OTHER, 4040));
                test_exp.addResultParam(new Param("Параметр 8", Param.P_OTHER, 3.1415));
                
                SaveLoadExpContainer slec = new SaveLoadExpContainer();
                slec.init();
                
                new SaveExpFrame(test_exp,slec).setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JButton jb_cancel;
    private javax.swing.JButton jb_save;
    private javax.swing.JComboBox jcb_sources;
    private javax.swing.JLabel jl_title;
    // End of variables declaration//GEN-END:variables
}
